/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2011 Bull S.A.S.
 * Contact: jonas-team@ow2.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 *
 * --------------------------------------------------------------------------
 * $Id: ProcessorAlarmCreatorTestCase.java 444 2011-08-16 16:24:00Z guillaume.sauthier $
 * --------------------------------------------------------------------------
 */


package org.osami.gateway.mediator.alarm.internal;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import fr.liglab.adele.cilia.Data;
import org.osami.gateway.alarm.IAlarm;
import org.testng.annotations.Test;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;

/**
 * A {@code ProcessorAlarmCreatorTestCase} is ...
 *
 * @author Guillaume Sauthier
 */
public class ProcessorAlarmCreatorTestCase {
    @Test
    public void testAlarmCreation() throws Exception {

        Date timestamp = new Date(System.currentTimeMillis());
        Data input = new Data(null);
        input.setProperty(IAlarm.ID_PROPERTY, "number-one");
        input.setProperty(IAlarm.DATE_PROPERTY, timestamp);
        input.setProperty(IAlarm.MESSAGE_PROPERTY, "hello");
        input.setProperty(IAlarm.SEVERITY_PROPERTY, "WARNING");

        ProcessorAlarmCreator creator = new ProcessorAlarmCreator();
        List<Data> out = creator.process(Collections.singletonList(input));

        assertThat(out.size(), is( equalTo(1) ));
        assertThat(out.get(0), is( instanceOf(Data.class) ));
        Data result = out.get(0);
        assertThat(result.getContent(), is( instanceOf(IAlarm.class) ));

        // Test fields
        IAlarm alarm = (IAlarm) result.getContent();
        assertThat(alarm.getIdentifier(), is( equalTo("number-one") ));
        assertThat(alarm.getDate(), is( equalTo(timestamp) ));
        assertThat(alarm.getMessage(), is( equalTo("hello") ));
        assertThat(alarm.getSeverity(), is( equalTo(IAlarm.Severity.WARNING) ));
    }
}
